package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.entity.WmMaterial;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.media.service.IWmChannelService;

import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 频道信息表 前端控制器
 * </p>
 *
 * @author mcm
 * @since 2021-11-02
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {

    // 注入服务接口
    @Autowired
    private IWmChannelService wMChannelService;

    /**
     * 根据名称模糊查询分页列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "根据名称模糊查询分页列表", notes = "author:mcm")  // value指名称  notes 备注
    @ApiImplicitParam(name = "dto", value = "查询对象", required = true, dataType = "ChannelDto")
    public ResponseResult listByName(@RequestBody ChannelDto dto) {
        return wMChannelService.listByName(dto);
    }

    @ApiOperation(value = "新增频道", notes = "author:mcm")
    @ApiImplicitParam(name = "entity", value = "频道对象", required = true, dataType = "WmChannel")
    @PostMapping
    public ResponseResult saveWmChannel(@RequestBody WmChannel entity){
        return wMChannelService.saveWmChannel(entity);
    }
    //查询所有频道
    @GetMapping("/channels")
    public ResponseResult channels() {
        List<WmChannel> list = wMChannelService.list();
        return ResponseResult.okResult(list);
    }

    //修改频道
    @PutMapping
    public ResponseResult updateWmChannel(@RequestBody WmChannel channel) {
        return wMChannelService.updateWmChannel(channel);
    }

    //删除频道
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return wMChannelService.deleteById(id);
    }

}
